import java.util.List;
import java.util.Map;

import com.qq.opensns.OpensnsException;
import com.qq.opensns.UserInfo;
import com.qq.opensns.pengyou.PengyouClient;

public class Test {
	// 第三方应用的基本信息
	String appid = "25882";
	String appname = "app25882";
	String appkey = "8d36e1f941b54a9c965a596e5bcccb7b";

	String openid = "0000000000000000000000001664F729";
	String openkey = "5EE68446EB675FA98DCF2AEDD0B3EC1F61BBAFE350DD975F";

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Test t = new Test();
		// t.testGetUserInfo();
		// t.testGetFriendList();
		// t.testGetEmotion();
		t.testGetMultiInfo();
		// t.testAll();
	}

	private void testGetUserInfo() {
		// 构造一个PengyouClient对象
		PengyouClient client = new PengyouClient(appid, appname, appkey);
		try {
			// 获取用户个人信息
			UserInfo user = client.getUserInfo(openid, openkey);

			// 获取用户的黄钻信息
			String vipInfo = "";
			if (user.isYearVip()) {
				vipInfo = "（年费黄钻用户 Lv." + String.valueOf(user.vipLevel()) + "）";
			} else if (user.isVip()) {
				vipInfo = "（黄钻用户 Lv." + String.valueOf(user.vipLevel()) + "）";
			}

			// 打印出用户的昵称、城市、头像链接
			System.out.println("用户昵称：" + user.getNickname() + vipInfo);
			System.out.println("所在城市：" + user.getProvince() + user.getCity());
			System.out.println("头像链接：" + user.getFigureUrl());
		} catch (OpensnsException e) {
			// e.printStackTrace();
		}
	}

	private void testGetFriendList() {
		// 构造一个PengyouClient对象
		PengyouClient client = new PengyouClient(appid, appname, appkey);

		try {
			// 获取好友列表：1 代表安装了本应用；true代表获取详细信息；0为列表页码
			List<UserInfo> friends = client.getFriendList(openid, openkey, 1,
					true, 0);

			System.out.println("用户的部分好友如下：");
			for (UserInfo friend : friends) {
				// 获取好友的签名档信息
				System.out.printf("[%s]%s \t（头像链接: %s）\n", friend.getGender(),
						friend.getNickname(), friend.getFigureUrl());
			}
		} catch (OpensnsException e) {
			System.out.printf("API调用出错。错误码为 %d，错误信息为： %s。", e.getErrorCode(),
					e.getMessage());
		}
	}

	private void testGetMultiInfo() {
		// 构造一个PengyouClient对象
		PengyouClient client = new PengyouClient(appid, appname, appkey);

		try {
			// 获取好友OpenID列表：1 代表安装了本应用；0为列表页码
			List<String> friends = client.getFriendOpenidList(openid, openkey,
					1, 0);
			// 获取这些好友的
			List<UserInfo> users = client
					.getMultiInfo(openid, openkey, friends);

			// 显示出用户ID和签名档
			System.out.println("和该用户一起使用本应用的部分好友如下：");
			for (UserInfo user : users) {

				// 获取用户的黄钻信息
				String vipInfo = "普通用户";
				if (user.isYearVip()) {
					vipInfo = "年费黄钻 ";
				} else if (user.isVip()) {
					vipInfo = "黄钻用户 ";
				}

				// 打印出用户的昵称、城市、头像链接
				System.out.printf("[%s]%s \t（%s Lv.%d）\n", user.getGender(),
						user.getNickname(), vipInfo, user.vipLevel());
			}
		} catch (OpensnsException e) {
			System.out.printf("API调用出错。错误码为 %d，错误信息为： %s。", e.getErrorCode(),
					e.getMessage());
		}
	}

	private void testGetEmotion() {
		PengyouClient client = new PengyouClient(appid, appname, appkey);

		try {
			// 获取好友OpenID列表：1 代表安装了本应用；0为列表页码
			List<String> friends = client.getFriendOpenidList(openid, openkey,
					1, 0);
			// 获取这些好友的签名档
			Map<String, String> emotions = client.getEmotion(openid, openkey,
					friends);

			// 显示出用户ID和签名档
			System.out.println("和该用户一起使用本应用的部分好友签名档如下：");
			for (String friend : friends) {
				System.out.println(friend + " : " + emotions.get(friend));
			}
		} catch (OpensnsException e) {
			System.out.printf("API调用出错。错误码为 %d，错误信息为： %s。", e.getErrorCode(),
					e.getMessage());
		}
	}

	private void testAll() {
		// 构造一个PengyouClient对象
		PengyouClient client = new PengyouClient(appid, appname, appkey);

		try {
			List<String> friends = client.getFriendOpenidList(openid, openkey,
					0, 0);

			System.out.println(client.getUserInfoData(openid, openkey)
					+ "\n---");
			System.out.println(client.getFriendListData(openid, openkey, 1,
					false, 0) + "\n---");
			System.out.println(client.getEmotionData(openid, openkey, friends)
					+ "\n---");
			System.out.println(client
					.getMultiInfoData(openid, openkey, friends) + "\n---");
			System.out.println(client.getIsFriendData(openid, openkey, openid)
					+ "\n---");
			System.out.println(client.getIsSetupedData(openid, openkey)
					+ "\n---");
			System.out.println(client.getIsVipData(openid, openkey) + "\n---");
		} catch (OpensnsException ex) {
			ex.printStackTrace();
		}
	}
}
